fix(python): fix snippet regressions in reference.md and docstrings#14668
Conversation
…h params in docstrings - Fix DynamicTypeLiteralMapper.convertEnum() to render enum references (e.g., Operand.GREATER_THAN) instead of string literals when using python_enums or forward_compatible_python_enums pydantic config - Fix build_default_snippet_kwargs() to include client_id and client_secret in OAuth client credentials docstring examples - Also fix synthesizeDefaultNamed() for consistent enum rendering Co-Authored-By: adi <aditya.arolkar@berkeley.edu>
🤖 Devin AI EngineerI'll be helping with this pull request! Here's what you should know: ✅ I will automatically:
Note: I can only respond to comments from users who have write access to this repository. ⚙️ Control Options:
|
There was a problem hiding this comment.
Claude Code Review
This repository is configured for manual code reviews. Comment @claude review to trigger a review and subscribe this PR to future pushes, or @claude review once for a one-time review.
Tip: disable this comment in your organization's Code Review settings.
SDK Generation Benchmark ResultsComparing PR branch against Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
…dantic_config Co-Authored-By: adi <aditya.arolkar@berkeley.edu>
SDK Generation Benchmark ResultsComparing PR branch against Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
…tructors in snippets
Since v4.62.0, reference.md and README snippets rendered objects as dict
literals when use_typeddict_requests was enabled, and discriminated unions
as dicts unconditionally. This regressed from the v1 generator which
always used Pydantic model constructors (e.g. OrderType_Market() instead
of {"type": "MARKET"}).
- Always use Pydantic constructors for objects in convertObject() and
synthesizeDefaultNamed(), removing the useTypedDictRequests() gate
- Add Pydantic constructor path for discriminated unions in
convertDiscriminatedUnion() with variant class resolution
- Add getDiscriminatedUnionVariantClassReference() to construct variant
class names (e.g. OrderType_Market from OrderType + Market)
Made-with: Cursor
…75495102-fix-python-sdk-snippet-regressions
Made-with: Cursor
SDK Generation Benchmark ResultsComparing PR branch against Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
SDK Generation Benchmark ResultsComparing PR branch against Full benchmark table (click to expand)
main (generator): generator-only time via --skip-scripts (includes Docker image build, container startup, IR parsing, and code generation — this is the same Docker-based flow customers use via |
Summary
Fixes three regressions in generated Python SDK snippets (reference.md, README, and docstrings) that were introduced when snippet generation moved from the Python v1 generator to the TypeScript v2 dynamic snippets generator in v4.62.0.
1. Enums rendered as strings
When
pydantic_config.enum_typeis set topython_enumsorforward_compatible_python_enums, enum parameters in reference.md/README snippets were rendered as raw strings (e.g.side="BUY") instead of enum references (SideTypeCode.BUY).Root cause:
DynamicTypeLiteralMapper.convertEnum()always emitted string literals and never checked the enum_type config. Additionally,SdkCustomConfigSchema.parse()silently strippedpydantic_configfrom the custom config before passing it to the dynamic snippets generator.Fix: Pass raw
config.customConfiginstead of the parsed/stripped version toDynamicSnippetsGenerator, and checkpydantic_config.enum_typeinconvertEnum()andsynthesizeDefaultNamed()to emit proper enum member access.2. Objects and discriminated unions rendered as dict literals
Objects and discriminated unions in snippets were rendered as dict literals (e.g.
order_type={"type": "MARKET"},instrument={"symbol": "AAPL US Equity"}) instead of Pydantic model constructors (OrderType_Market(),InstrumentSymbol(symbol="AAPL US Equity")).Root cause:
convertObject()was gated onuseTypedDictRequests(), andconvertDiscriminatedUnion()had no Pydantic constructor path at all — it always emitted TypedDicts.Fix: Always use Pydantic model constructors for both objects and discriminated unions in snippets. Added
getDiscriminatedUnionVariantClassReference()to resolve variant class names (e.g.OrderType+Market→OrderType_Market).3. Missing OAuth credentials in docstring snippets
OAuth client credentials client instantiation in docstrings showed
client = Orders()with no auth params.Root cause:
build_default_snippet_kwargs()only includes params without defaults, butclient_id/client_secrethaveos.getenv(...)defaults.Fix: Explicitly append
client_id/client_secretwith placeholder values when OAuth client credentials are configured.Test plan